/*
 * @lc app=leetcode.cn id=13 lang=javascript
 *
 * [13] 罗马数字转整数
 */

// @lc code=start
/**
 * @param {string} s
 * @return {number}
 */
var romanToInt = function (s) {
    let sum = 0
    for (let i = 0; i < s.length; i++) {
        switch (s[i]) {
            case 'I':
                switch (s[i + 1]) {
                    case 'V':
                        sum = sum + 4;
                        i++;
                        break
                    case 'X':
                        sum = sum + 9
                        i++;
                        break
                    default:
                        sum = sum + 1
                }
                break
            case 'X':
                switch (s[i + 1]) {
                    case 'L':
                        sum = sum + 40;
                        i++;
                        break
                    case 'C':
                        sum = sum + 90
                        i++;
                        break
                    default:
                        sum = sum + 10
                }
                break
            case 'C':
                switch (s[i + 1]) {
                    case 'D':
                        sum = sum + 400;
                        i++;
                        break
                    case 'M':
                        sum = sum + 900
                        i++;
                        break
                    default:
                        sum = sum + 100
                }
                break
            case 'V':
                sum = sum + 5;
                break
            case 'L':
                sum = sum + 50;
                break
            case 'D':
                sum = sum + 500;
                break
            case 'M':
                sum = sum + 1000;
                break
        }
    }
    return sum
};
// @lc code=end